#ifndef _DYNAMICARRAY_H_
#define _DYNAMICARRAY_H_

#include <iostream>
#define ElementType void*
class DynamicArray
{
public:
    DynamicArray(void(*free)(ElementType));
    ~DynamicArray();
    DynamicArray(const DynamicArray& d);
    DynamicArray& operator=(const DynamicArray&d);

    void show(void (*func)(ElementType));
    //扩容
    void Resize(int newCapacity);
    //尾插法
    void InsertTail(ElementType element);
    //头插法
    void InsertHead(ElementType element);
    //中间插入
    void InsertByIndex(ElementType element,int index);
    //按位置删除
    void RemoveByIndex(int index);
    //按值删除
    void RemoveByElement(ElementType element,bool(*isEqual)(ElementType,ElementType));
    //按位置修改
    void UpDataByIndex(int index,ElementType newElement);
    //按值修改
    void UpDataByElement(ElementType oldValue,ElementType newValue);
    //按位置查找
    ElementType& operator[](int index);
    //按值查找位置
    DynamicArray FindByElement(ElementType element);
    //排序
    //设置排序回调
    void SetSortCallBack(bool (*Compare)(ElementType,ElementType));
    void Sort();
    //二分查找
    int BinarySearch(ElementType element);
    //去重
    void Deduplicate();
    //合并
    DynamicArray Merge(const DynamicArray& d);
    friend std::ostream& operator<<(std::ostream& os,const DynamicArray& d);
private:
    void Sort(int start,int end);
    ElementType *a;
    int size;
    int capacity;
    void(*free)(ElementType);
    bool (*Compare)(ElementType,ElementType);
};

std::ostream& operator<<(std::ostream& os,const DynamicArray& d);


#endif